package cn.cxion.chat.kit.conversation.ext;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.view.View;

import com.blankj.utilcode.util.PathUtils;
import com.lqr.imagepicker.ImagePicker;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;

import cn.cxion.chat.R;
import cn.cxion.chat.app.activity.AppointmentActivity;
import cn.cxion.chat.app.bean.AppointmentInfo;
import cn.cxion.chat.app.bean.AppointmentLocale;
import cn.cxion.chat.app.constant.Constant;
import cn.cxion.chat.app.util.LogUtil;
import cn.cxion.chat.app.util.StringUtil;
import cn.cxion.chat.kit.annotation.ExtContextMenuItem;
import cn.cxion.chat.kit.conversation.ext.core.ConversationExt;
import cn.cxion.chat.kit.third.utils.ImageUtils;
import cn.wildfirechat.message.TextMessageContent;
import cn.wildfirechat.message.TypingMessageContent;
import cn.wildfirechat.model.Conversation;


public class AppointmentExt extends ConversationExt {

    /**
     * @param containerView 扩展view的container
     * @param conversation
     */
    @ExtContextMenuItem(title = "预约客户")
    public void pickCustomer(View containerView, Conversation conversation) {
        TypingMessageContent content = new TypingMessageContent(TypingMessageContent.TYPING_TEXT);
        conversationViewModel.sendMessage(content);
        Intent intent = AppointmentActivity.getIntents(context, Constant.APPOINTMENTCUSTOMER);
        startActivityForResult(intent, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        LogUtil.print("预约   " + resultCode);
        if (resultCode == 100) {
            AppointmentInfo info = (AppointmentInfo) data.getSerializableExtra("appointmentInfo");
            LogUtil.print(info.getContent());
            TextMessageContent txtContent = new TextMessageContent(info.getContent());
            conversationViewModel.sendTextMsg(txtContent);

        }
//        File imageFileThumb=new File(PathUtils.getExternalAppFilesPath()+"/99.jpg");
//        conversationViewModel.sendImgMsg(imageFileThumb,imageFileThumb);
//        if (resultCode == Activity.RESULT_OK) {
//            if (data != null) {
//                //是否发送原图
//                boolean compress = data.getBooleanExtra(ImagePicker.EXTRA_COMPRESS, true);
//                ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
//                for (ImageItem imageItem : images) {

//                    File imageFileThumb;
//                    File imageFileSource;
        // FIXME: 2018/11/29 压缩, 不是发原图的时候，大图需要进行压缩
//                    if (isOrig) {
//                    imageFileSource = new File(PathUtils.getExternalAppFilesPath()+"/99.jpg");
//                    imageFileThumb = ImageUtils.genThumbImgFile(PathUtils.getExternalAppFilesPath()+"/99.jpg");
//                    } else {
//                        //压缩图片
//                        // TODO  压缩的有问题
//                        imageFileSource = ImageUtils.genThumbImgFileEx(imageItem.path);
//                        //imageFileThumb = ImageUtils.genThumbImgFile(imageFileSource.getAbsolutePath());
//                        imageFileThumb = imageFileSource;
//                    }
//        File file = new File(PathUtils.getExternalAppFilesPath()+"/99.jpg");
//        File imageFileThumb = ImageUtils.genThumbImgFile(PathUtils.getExternalAppFilesPath()+"/99.jpg");
//        conversationViewModel.sendImgMsg(imageFileThumb, file);

//                }
//            }
//        }
    }


    @Override
    public int priority() {
        return 100;
    }

    @Override
    public int iconResId() {
        return R.mipmap.appointment;
    }

    @Override
    public String title(Context context) {
        return "预约客户";
    }
}
